﻿<%@ Page Theme="POSSystem" Title="POSSystem | Customer" Language="C#" MasterPageFile="~/Application.Master"
    AutoEventWireup="true" CodeBehind="Customer.aspx.cs" Inherits="WebUI.Customer" %>

<%@ Register Src="~/Controls/SysControls/PageHeader.ascx" TagPrefix="uc" TagName="PageHeader" %>
<%@ Register Src="~/Controls/POSControls/CustomerListCtrl.ascx" TagName="CustomerList"
    TagPrefix="uc" %>
<%@ Register Src="~/Controls/SysControls/GridFilterPaging.ascx" TagName="GridFilterPaging"
    TagPrefix="uc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ApplicationHeadHolder" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ApplicationContentHolder" runat="server">

    <script type="text/javascript">
        function onAddCust() {
            var id = getSelectedItemID<%=lstCustomer.ClientID %>();
            var returnValue = window.showModalDialog('<%=GetCustEditPageLink() %>' + '&mode=new', '', 'dialogWidth=450px;dialogHeight=300px;resizable=no;help=no;unadorned=yes;');

            return returnValue > 0;
        }

        function onEditCust() {
            var id = getSelectedItemID<%=lstCustomer.ClientID %>();
            if(id == null){
                alert("No item was selected!");
                return false;
            }
            var returnValue = window.showModalDialog('<%=GetCustEditPageLink() %>' + '&mode=edit&id=' + id, '', 'dialogWidth=450px;dialogHeight=300px;resizable=no;help=no;unadorned=yes;');
            return returnValue > 0;
        }
        
        function onShowCustHist(){
            var id = getSelectedItemID<%=lstCustomer.ClientID %>();
            if(id == null){
                alert("No item was selected!");
                return false;
            }
                
            var returnValue = window.showModalDialog('<%=GetCustInvoiceHistory() %>' + 'custid=' + id, '', 'dialogWidth=800px;dialogHeight=600px;resizable=yes;help=no;unadorned=yes;');

            return false;
        }
        
        function onShowCustPayHist(){
            var id = getSelectedItemID<%=lstCustomer.ClientID %>();
            if(id == null){
                alert("No item was selected!");
                return false;
            }
                
            var returnValue = window.showModalDialog('<%=GetCustPaymentHistory() %>' + 'custid=' + id, '', 'dialogWidth=800px;dialogHeight=600px;resizable=yes;help=no;unadorned=yes;');

            return false;
        }

        function onRemoveCust() {
            var id = HasCheckedItems<%=lstCustomer.ClientID %>();
            if(id == false){
                alert("No item was selected!");
                return false;
            }
            
            return confirm("This action will delete all checked items. Do you want to continue?");
        }
        
        function showPrintDlg(key){
            var returnValue = window.showModalDialog(key, '', 'dialogWidth=800px;dialogHeight=600px;resizable=yes;help=no;unadorned=yes;');
        }
        
        var selectBtn = null;
        function btnGroup_click(btn){
            var hidSelectedGroup = document.getElementById("<%=hidSelectedGroup.ClientID%>");
            selectBtn = document.getElementById("btn_" + hidSelectedGroup.value);
            
            if(selectBtn != null){
                if(selectBtn.className){
                    selectBtn.className = "";
                }
                else{
                    selectBtn.setAttribute("class", "");
                }
            }
            
            if(btn.className){
                btn.className = "sortButtonSelected";
            }
            else{
                btn.setAttribute("class", "sortButtonSelected");
            }

            hidSelectedGroup.value = btn.getAttribute("GroupID");

            var btnLoadByGroup = document.getElementById("<%=btnLoadByGroup.ClientID%>");
            if (btnLoadByGroup != null)
                btnLoadByGroup.click();
        }
        
        function onAddCustType() {
            var returnValue = window.showModalDialog('<%=GetGroupEditPageLink() %>' + '&mode=new', '', 'dialogWidth=450px;dialogHeight=200px;resizable=no;help=no;unadorned=yes;');

            return returnValue > 0;
        }

        function onEditCustType(btn) {
            var hidSelectedGroup = document.getElementById("<%=hidSelectedGroup.ClientID%>");
            if (hidSelectedGroup.value == '' || hidSelectedGroup.value == undefined) {
                alert('Please select a Group!');
                return false;
            }

            var returnValue = window.showModalDialog('<%=GetGroupEditPageLink() %>' + '&mode=edit&id=' + hidSelectedGroup.value,
                '', 'dialogWidth=450px;dialogHeight=200px;resizable=no;help=no;unadorned=yes;');

            return returnValue > 0;
        }

        function onRemoveCustType() {
            var hidSelectedGroup = document.getElementById("<%=hidSelectedGroup.ClientID%>");

            if (hidSelectedGroup.value == '' || hidSelectedGroup.value == undefined || hidSelectedGroup.value == '-999') {
                alert('Please select a Group!');
                return false;
            }
            return confirm("Do you want to delete the selected Group?");
        }
        
        function onResetPwd()
        {
            var id = getSelectedItemID<%=lstCustomer.ClientID %>();
            if(id == null){
                alert("Please select a customer!");
                return false;
            }
            
            var hid = document.getElementById("<%= hidSelectedCust.ClientID %>");
            hid.value = id;

           return confirm("Do you want to reset password for the selected customer?");
        }
    </script>

    <uc:PageHeader ID="pageHeader" Text="Customers" ImageURL="~/Images/90279.png" runat="server" />
    <table width="100%">
        <tr>
            <td style="width: 200px; text-align: left; vertical-align: top">
                <asp:Panel ID="panel1" runat="server" class="primaryPanel">
                    <div class="titleBar">
                        <asp:Label ID="Label1" runat="server" CssClass="titleContent">Group</asp:Label>
                    </div>
                    <div class="primaryFrameNoBorder">
                        <div>
                            <asp:UpdatePanel ID="updateLeft" runat="server" UpdateMode="Conditional">
                                <ContentTemplate>
                                    <table class="toolbar" width="100%">
                                        <tr>
                                            <td>
                                                <asp:LinkButton class="tbbutton" ID="btnAddCustType" runat="server" OnClientClick="return onAddCustType();"
                                                    OnClick="btnAddType_OnClick">
                                                    <img src="Images/AddRecord.gif" /><asp:Label ID="label2" runat="server" Text="Add"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnEditCustType" runat="server" OnClientClick=" return onEditCustType();"
                                                    OnClick="btnAddType_OnClick">
                                                    <img src="Images/Edit.gif" /><asp:Label ID="label3" runat="server" Text="Edit"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnRemoveCustType" runat="server" OnClientClick="return onRemoveCustType();"
                                                    OnClick="btnRemoveType_OnClick">
                                                    <img src="Images/Delete.gif" /><asp:Label ID="label4" runat="server" Text="Delete"></asp:Label>
                                                </asp:LinkButton>
                                            </td>
                                        </tr>
                                    </table>
                                    <asp:UpdatePanel ID="updateGroup" runat="server" UpdateMode="Conditional">
                                        <ContentTemplate>
                                            <div id='divGroup' runat="server">
                                            </div>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </div>
                    </div>
                </asp:Panel>
            </td>
            <td style="text-align: left; vertical-align: top;">
                <asp:Panel ID="panelCategory" runat="server" class="primaryPanel" DefaultButton="btnSearchCust" >
                    <div class="titleBar">
                        <asp:Label ID="lblTitle1" runat="server" CssClass="titleContent">Customer List</asp:Label>
                    </div>
                    <div class="primaryFrameNoBorder">
                        <div>
                            <asp:UpdatePanel ID="updateToolBar" runat="server" UpdateMode="Conditional">
                                <Triggers>
                                    <asp:PostBackTrigger ControlID="btnExcel" />
                                </Triggers>
                                <ContentTemplate>
                                    <table width="100%" class="toolbar">
                                        <tr>
                                            <td style='vertical-align: middle'>
                                                <asp:LinkButton class="tbbutton" ID="btnAddCust" runat="server" OnClientClick="return onAddCust();"
                                                    OnClick="btnAddCust_OnClick">
                                                    <img src="Images/AddRecord.gif" /><asp:Label ID="label5" runat="server" Text="Add"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnEditCust" runat="server" OnClientClick=" return onEditCust();"
                                                    OnClick="btnAddCust_OnClick">
                                                    <img src="Images/Edit.gif" /><asp:Label ID="label6" runat="server" Text="Edit"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnDeleteCust" runat="server" OnClientClick="return onRemoveCust();"
                                                    OnClick="btnRemoveCust_OnClick">
                                                    <img src="Images/Delete.gif" /><asp:Label ID="label7" runat="server" Text="Delete"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnResetPwd" runat="server" OnClientClick="return onResetPwd();"
                                                    OnClick="btnResetPwd_OnClick">
                                                    <img src="Images/reset.png" /><asp:Label ID="label13" runat="server" Text="Reset PWD"></asp:Label>
                                                </asp:LinkButton>
                                                <img src="Images/tbSep.png" />
                                                <asp:LinkButton class="tbbutton" ID="btnInvoiceHistory" runat="server" OnClientClick=" return onShowCustHist();">
                                                    <img src="Images/Invoice1.png" /><asp:Label ID="label10" runat="server" Text="Invoice History"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnPaymentHistory" runat="server" OnClientClick="return onShowCustPayHist();">
                                                    <img src="Images/creditcard_32.png" /><asp:Label ID="label12" runat="server" Text="Payment History"></asp:Label>
                                                </asp:LinkButton>
                                                <img src="Images/tbSep.png" />
                                                <asp:LinkButton class="tbbutton" ID="btnPrintCust" runat="server" OnClick="btnPrintCust_OnClick">
                                                    <img src="Images/print.gif" /><asp:Label ID="label8" runat="server" Text="Print"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnExcel" runat="server" OnClick="btnExcel_OnClick">
                                                    <img src="Images/excel.gif" /><asp:Label ID="label9" runat="server" Text="Export"></asp:Label>
                                                </asp:LinkButton>
                                                <img src="Images/tbSep.png" />
                                                <asp:TextBox ID="txtSearchCust" runat="server"></asp:TextBox>
                                                <asp:LinkButton class="tbbutton" ID="btnSearchCust" runat="server" OnClick="btnSearchCust_OnClick">
                                                    <img src="Images/search.png" />
                                                </asp:LinkButton>
                                                <img src="Images/tbSep.png" />
                                                <asp:LinkButton class="tbbutton" ID="btnReload" runat="server" OnClick="btnReload_OnClick">
                                                    <img src="Images/reload.png" /><asp:Label ID="label11" runat="server" Text="Reload"></asp:Label>
                                                </asp:LinkButton>
                                            </td>
                                        </tr>
                                    </table>
                                    <asp:UpdatePanel ID="updateGrid" runat="server" UpdateMode="Conditional">
                                        <ContentTemplate>
                                            <uc:CustomerList ID="lstCustomer" Width="100%" runat="server" AllowPaging="true"
                                                AllowSelecting="true" AllowSorting="true" SaveOnCommit="false" />
                                            <asp:HiddenField ID="hidSelectedGroup" runat="server" />
                                            <asp:HiddenField ID="hidSelectedCust" runat="server" />
                                            <asp:Button Style="display: none" ID="btnLoadByGroup" runat="server" OnClick="btnLoadByGroup_OnClick" />
                                            <div style="height: 10px">
                                                &nbsp;</div>
                                            <uc:GridFilterPaging ID="gridFilterPaging" runat="server" FilteredField="CustomerName"
                                                OnNeedListControl="gridFilterPaging_OnNeedListControl" />
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </div>
                    </div>
                </asp:Panel>
            </td>
        </tr>
    </table>
</asp:Content>
